<template>
  <a-table
    ref="table"
    size="middle"
    :scroll="{x:true}"
    bordered
    rowKey="orgCode"
    :columns="columns"
    :dataSource="dataSource"
    :pagination="ipagination"
    :loading="loading"
    class="j-table-force-nowrap"
    @change="handleTableChange">
  </a-table>
</template>

<script>
import { getAction } from '@api/manage'

export default {
  name: 'AllSummaryOrgList.vue',
  props: {
    date:{
      type: String,
      required: false
    },
    scoreType:{
      type: Number,
      required: true
    }
  },
  watch:{
    date(){
      this.loadData();
    },
  },
  data(){
    return {
      columns:[
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },

        {
          title:'部门',
          align:"center",
          dataIndex: 'departName'
        },
        {
          title: '教学数量(专职教师)',
          children: [
            {
              title:'总课时量',
              align:"center",
              dataIndex: 'totalClasstime',
              sorter: (a, b) => a.totalClasstime - b.totalClasstime,
            },
            {
              title:'人均课时量',
              align:"center",
              dataIndex: 'avgClasstime',
              sorter: (a, b) => a.avgClasstime - b.avgClasstime,
            },
            {
              title:'总分',
              align:"center",
              dataIndex: 'classScore',
              sorter: (a, b) => a.classScore - b.classScore,
            },
            {
              title:'人均积分',
              align:"center",
              dataIndex: 'avgClassScore',
              sorter: (a, b) => a.avgClassScore - b.avgClassScore,
            },
          ],
        },
        {
          title: '教学建设(专职教师)',
          children: [
            {
              title:'总分',
              align:"center",
              dataIndex: 'buildingScore',
              sorter: (a, b) => a.buildingScore - b.buildingScore,
            },
            {
              title:'人均积分',
              align:"center",
              dataIndex: 'avgBuildingScore',
              sorter: (a, b) => a.avgBuildingScore - b.avgBuildingScore,
            },
          ],
        },
        {
          title: '荣誉奖励(专职教师)',
          align:"center",
          children: [
            {
              title:'总分',
              align:"center",
              dataIndex: 'honourScore',
              sorter: (a, b) => a.honourScore - b.honourScore,
            },
            {
              title:'人均积分',
              align:"center",
              dataIndex: 'avgHonourScore',
              sorter: (a, b) => a.avgHonourScore - b.avgHonourScore,
            },
          ],
        },
        {
          title: '科研(专职教师)',
          children: [
            {
              title:'总分',
              align:"center",
              dataIndex: 'researchScore',
              sorter: (a, b) => a.researchScore - b.researchScore,
            },
            {
              title:'人均积分',
              align:"center",
              dataIndex: 'avgResearchScore',
              sorter: (a, b) => a.avgResearchScore - b.avgResearchScore,
            },
          ],
        },
        {
          title: '总积分(专职教师)',
          children: [
            {
              title:'总积分',
              align:"center",
              dataIndex: 'totalScore',
              sorter: (a, b) => a.totalScore - b.totalScore,
            },
            {
              title:'人均积分',
              align:"center",
              dataIndex: 'avgTotalScore',
              sorter: (a, b) => a.avgTotalScore - b.avgTotalScore,
            }
          ],
        },

      ],
      ipagination: {
        pageSize: 15
      },
      loading:false,
      dataSource:[],
      url:{
        list: 'common/totalScore/listSummaryTotalScore'
      }
    }
  },
  methods:{
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      console.log(pagination)
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      this.loadData();
    },
    loadData(){
      if(!this.url.list){
        this.$message.error("请设置url.list属性!")
        return
      }

      let params = {date:this.date, orgCode:'A05', scoreType:this.scoreType}
      this.loading = true;
      getAction(this.url.list, params).then((res) => {
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records||res.result;
          if(res.result.total)
          {
            this.ipagination.total = res.result.total;
          }else{
            this.ipagination.total = 0;
          }
        }
        if(res.code===510){
          this.$message.warning(res.message)
        }
        this.loading = false;
      })
    }
  },
  created() {
    this.loadData();
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>